// import { AnimationComponent, profiler } from 'cc';
// import { TcbManager } from './../../framework/tcbManager';
// import { _decorator, Component, Node, EditBoxComponent, LabelComponent, error } from 'cc';
// import { DisplayManager } from '../../core/displayManager';
// import { GameState, Player } from '../../core/GameState';
// import { MgobeUtil } from '../../core/mgobeUtil';
// import {ClientEvent }from '../../framework/clientEvent';
// import i18n from '../../i18nMaster/runtime-scripts/LanguageData';
// import { Constant } from '../../framework/constant';
// const { ccclass, property } = _decorator;
//
// /**
//  * Predefined variables
//  * Name = Ready2
//  * DateTime = Thu Sep 02 2021 17:35:37 GMT+0800 (中国标准时间)
//  * Author = yanli.huang
//  * FileBasename = ready2.ts
//  * FileBasenameNoExtension = ready2
//  * URL = db://assets/script/ui/ready/ready2.ts
//  * ManualUrl = https://docs.cocos.com/creator/3.3/manual/zh/
//  *
//  */
//
// const COUNT_DOWN_TIME: number = 3;
// @ccclass('Ready')
// export class Ready extends Component {
//     @property([Node])
//     public aryNodeTips: Node[] = [];
//
//     @property([Node])
//     public aryNodeCheck: Node[] = [];
//
//     @property([Node])
//     public aryNodeWait: Node[] = [];
//
//     @property([LabelComponent])
//     public aryPlayerName: LabelComponent[] = [];
//
//     @property(LabelComponent)
//     public lbTips: LabelComponent = null!;
//
//     @property(Node)
//     public ndReady: Node = null!;
//
//     @property(Node)
//     public ndInit: Node = null!;
//
//     @property(Node)
//     public ndJoin: Node = null!;
//
//     @property(EditBoxComponent)
//     public openIdEditBox: EditBoxComponent = null!;
//
//     @property(EditBoxComponent)
//     public roomIdEditBox: EditBoxComponent = null!;
//
//     @property(AnimationComponent)
//     public aniGuideTip: AnimationComponent = null!;//微信平台提示
//
//     private _parent: DisplayManager = null!;
//     private _isReady: boolean = false;
//     private _countDownTime: number = 0;
//     private _roomId: string = '';
//     private _isGuide: boolean = false;//是否已经展示过引导了
//     private _debugClickTimes: number = 0;//调试点击次数
//
//     start () {
//         this.openIdEditBox.node.active = true;
//         this.ndInit.active = true;
//         this.roomIdEditBox.node.active = false;
//         this.ndJoin.active = false;
//
//         //-ignore
//         if (window.wx) {
//             this.ndInit.active = false;
//             this.openIdEditBox.node.active = false;
//         }
//     }
//
//     onEnable () {
//         ClientEvent.on(Constant.EVENT_NAME.ON_GET_ROOM_ID, this._onGetRoomId, this);
//     }
//
//     onDisable () {
//         ClientEvent.off(Constant.EVENT_NAME.ON_GET_ROOM_ID, this._onGetRoomId, this);
//     }
//
//     public show(parent: DisplayManager) {
//         this._parent = parent;
//         this.aniGuideTip.node.active = false;
//
//         if (this._isGuide) {
//             this._countDownTime = COUNT_DOWN_TIME;
//             this.lbTips.string = i18n.t("ready.countdown%{value}", { value: Math.ceil(this._countDownTime).toString()});
//         } else {
//             this._isGuide = true;
//             //@ts-ignore 房主才展示提示
//             if (window.wx) {
//                 this.aniGuideTip.node.active = true;
//
//                 this.scheduleOnce(()=>{
//                     this.aniGuideTip.play("guideTipsHide");
//                 }, 4)
//             }
//         }
//
//         this._isReady = false;
//         this.ndReady.active = false;
//         if (this._roomId !== '') {
//             this.ndReady.active = true;
//         }
//         this._updatePlayerState();
//
//         //@ts-ignore
//         if (window.wx) {
//             this.onInitBtnClick();
//         }
//
//         this.aryPlayerName.forEach((lbCom: LabelComponent, idx: number)=>{
//             lbCom.string = i18n.t("ready.player%{value}", {value: idx + 1});
//         })
//
//         this._debugClickTimes = 0;
//         profiler.hideStats();
//     }
//
//     public onReadyBtnClick() {
//         this.ndReady.active = false;
//         MgobeUtil.instance.changeCustomPlayerStatus(Constant.CUSTOM_PLAYER_STATUS.READY);
//     }
//
//     public onJoinBtnClick() {
//         this.ndJoin.active = false;
//         MgobeUtil.instance.joinRoom(this.roomIdEditBox.string);
//     }
//
//     public onInitBtnClick() {
//         this.ndInit.active = false;
//         this.openIdEditBox.node.active = false;
//
//         //@ts-ignore
//         if (window.wx) {
//             TcbManager.instance.onGotUserInfo({}, (openId: string)=>{
//                 //@ts-ignore
//                 console.log("###openId", openId, "roomId", window.roomId);
//
//                 MgobeUtil.instance.initSDK(openId, '', '', () => {
//                     //如果是从分享进入的，则会获取房间号，直接进入房间就好了
//                     //@ts-ignore
//                     if (window.roomId) {
//                         //@ts-ignore
//                         MgobeUtil.instance.joinRoom(window.roomId);
//                     } else {
//                         this.onJoinBtnClick();
//                     }
//                 });
//             });
//         } else {
//             if (!this.openIdEditBox.string) return;
//             MgobeUtil.instance.initSDK(this.openIdEditBox.string, '', '', () => {
//                 this.ndJoin.active = true;
//                 this.roomIdEditBox.node.active = true;
//             });
//         }
//     }
//
//     private _updatePlayerState() {
//         let gameState: GameState = this._parent.logicManager.currentGameState;
//         let players: Array<Player> = gameState.players;
//
//         for (let idx = 0; idx < players.length; idx++) {
//             let lbTips: LabelComponent = this.aryNodeTips[idx].getComponent(LabelComponent) as LabelComponent;
//             let player: Player = players[idx];
//             if (!player.channel) {
//                 this._showPlayerReady(idx, false);
//                 continue;
//             }
//
//             if (player.channel.openId) {
//                 this.aryPlayerName[idx].string = player.channel.name;
//             }
//
//             switch(player.channel.state) {
//                 case Constant.CUSTOM_PLAYER_STATUS.CONNECTED:
//                     this._showPlayerReady(idx, false);
//                     lbTips.string = i18n.t("ready.waitPrepare");
//                     this.aryNodeWait[idx].active = false;
//                     break;
//                 case Constant.CUSTOM_PLAYER_STATUS.UNCONNECTED:
//                     lbTips.string = i18n.t("ready.waitConnect");
//                     this._showPlayerReady(idx, false);
//                     break;
//                 case Constant.CUSTOM_PLAYER_STATUS.READY:
//                     this._showPlayerReady(idx, true);
//                     break
//             }
//         }
//
//         this._checkStart();
//     }
//
//     private _showPlayerReady (idx: number, isReady: boolean) {
//         this.aryNodeTips[idx].active = !isReady;
//         this.aryNodeWait[idx].active = !isReady;
//         this.aryNodeCheck[idx].active = isReady;
//     }
//
//     private _checkStart(){
//         let players: Array<Player> = this._parent.logicManager.currentGameState.players;
//         let result: Array<Player> = players.filter((value: Player) => {
//             return value.channel && value.channel.state === Constant.CUSTOM_PLAYER_STATUS.READY;
//         });
//         if (result.length >= Constant.MIN_PLAYER) {
//             this._isReady = true;
//             this._countDownTime = COUNT_DOWN_TIME;
//          } else {
//              this._isReady = false;
//          }
//     }
//
//     update (deltaTime: number) {
//         // Your update function goes here.
//         if (this._isReady) {
//             //正准备进入游戏
//             if (this._countDownTime <= 0) {
//                 return;
//             }
//
//             this._countDownTime -= deltaTime;
//
//             this.lbTips.string = i18n.t("ready.countdown%{value}", { value: Math.ceil(this._countDownTime).toString()});
//
//             if (this._countDownTime <= 0) {
//                 //可以进入游戏了
//                 this._parent.gameStart();
//
//             }
//         }
//     }
//
//     private _onGetRoomId(roomId: string, readyState: boolean) {
//         if (!roomId) {
//             console.error("###房间号错误", roomId);
//             return;
//         }
//
//         this._roomId = roomId;
//         this.roomIdEditBox.string = roomId;
//         this.ndReady.active = !readyState;
//         this._updatePlayerState();
//         //@ts-ignore
//         window.roomId = roomId;
//     }
//
//     public onBtnDebugClick () {
//         this._debugClickTimes += 1;
//
//         if (this._debugClickTimes >= 2) {
//             profiler.showStats();
//             this._debugClickTimes = 0;
//         } else if (profiler.isShowingStats()) {
//             profiler.hideStats();
//             this._debugClickTimes = 0;
//         }
//     }
// }
//
// /**
//  * [1] Class member could be defined like this.
//  * [2] Use `property` decorator if your want the member to be serializable.
//  * [3] Your initialization goes here.
//  * [4] Your update function goes here.
//  *
//  * Learn more about scripting: https://docs.cocos.com/creator/3.3/manual/zh/scripting/
//  * Learn more about CCClass: https://docs.cocos.com/creator/3.3/manual/zh/scripting/ccclass.html
//  * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.3/manual/zh/scripting/life-cycle-callbacks.html
//  */
